// createWebHashHistory 是hash模式就是访问链接带有#
// createWebHistory  是history模式
import { createRouter, createWebHashHistory, createWebHistory } from "vue-router"

const routes = [
    {
        path: "/",
        name: "Login",
        meta: {
            title: "登录",
        },
        component: () => import("../views/Login.vue"),
    },
    {
        path: "/Home",
        name: "Home",
        meta: {
            title: "控制台",
        },
        component: () => import("../views/Home.vue"),
    },
	{
		path: "/System/Menu",
		name: "Menu",
	    meta: {
	        title: "菜单管理",
	    },
	    component: () => import("../views/Manu/ManuList.vue"),
	},
	{
		path: "/System/Admin",
	    name: "AdminList",
	    meta: {
	        title: "管理员列表",
	    },
	    component: () => import("../views/Manu/AdminList.vue"),
	},
	{
		path: "/System/Role",
	    name: "ManageRole",
	    meta: {
	        title: "角色管理",
	    },
	    component: () => import("../views/Manu/ManageRole.vue"),
	},
	{
	    path: "/ManageRoleAdd",
	    name: "ManageRoleAdd",
	    meta: {
	        title: "添加角色",
			showBread:true
	    },
	    component: () => import("../views/Manu/ManageRoleAdd.vue"),
	},
	{
	    path: "/ManageRoleEdit",
	    name: "ManageRoleEdit",
	    meta: {
	        title: "编辑角色",
			showBread:true
	    },
	    component: () => import("../views/Manu/ManageRoleEdit.vue"),
	},
	{
	    path: "/ImgClass",
	    name: "ImgClass",
	    meta: {
	        title: "图库分类"
	    },
	    component: () => import("../views/Manu/ImgClass.vue"),
	},
	{
	    path: "/UpdateApp",
	    name: "UpdateApp",
	    meta: {
	        title: "更新APP"
	    },
	    component: () => import("../views/Manu/UpdateApp.vue"),
	},
	{
	    path: "/SystemSettings",
	    name: "SystemSettings",
	    meta: {
	        title: "系统配置"
	    },
	    component: () => import("../views/Manu/SystemSettings.vue"),
	},
	{
	    path: "/Kefu",
	    name: "Kefu",
	    meta: {
	        title: "系统配置"
	    },
	    component: () => import("../views/Manu/Kefu.vue"),
	},
	{
	    path: "/ImgList",
	    name: "ImgList",
	    meta: {
	        title: "图库列表"
	    },
	    component: () => import("../views/Manu/ImgList.vue"),
	},
	{
	    path: "/Rider",
	    name: "Rider",
	    meta: {
	        title: "骑手列表",
	    },
	    component: () => import("../views/Member/RiderList.vue"),
	},
	{
	    path: "/MemberList",
	    name: "MemberList",
	    meta: {
	        title: "会员列表",
	    },
	    component: () => import("../views/Member/MemberList.vue"),
	},
	{
	    path: "/MemberDetail",
	    name: "MemberDetail",
	    meta: {
	        title: "会员详情",
			showBread: true,
	    },
	    component: () => import("../views/Member/MemberDetail.vue"),
	},
	{
	    path: "/SetBind",
	    name: "SetBind",
	    meta: {
	        title: "设置上级",
			showBread: true,
	    },
	    component: () => import("../views/Member/SetBind.vue"),
	},
	{
	    path: "/DownUser",
	    name: "DownUser",
	    meta: {
	        title: "查看下级",
			showBread: true,
	    },
	    component: () => import("../views/Member/DownUser.vue"),
	},
	{
	    path: "/MemberLevel",
	    name: "MemberLevel",
	    meta: {
	        title: "会员等级",
	    },
	    component: () => import("../views/Member/MemberLevel.vue"),
	},
	
    {
        path: "/News/NewsClass",
        name: "NewsClass",
        meta: {
            title: "文章分类",
        },
        component: () => import("../views/News/NewsClass.vue"),
    },
    {
        path: "/NewsList",
        name: "NewsList",
        meta: {
            title: "文章列表",
        },
        component: () => import("../views/News/NewsList.vue"),
    },
    {
        path: "/News/NewsAdd",
        name: "NewsAdd",
        meta: {
            title: "文章添加",
            showBread: true,
        },
        component: () => import("../views/News/NewsAdd.vue"),
    },
    {
        path: "/News/NewsEdit",
        name: "NewsEdit",
        meta: {
            title: "文章编辑",
            showBread: true,
        },
        component: () => import("../views/News/NewsEdit.vue"),
    },
	{
	    path: "/help",
	    name: "help",
	    meta: {
	        title: "使用帮助",
	    },
	    component: () => import("../views/News/help.vue"),
	},
	{
	    path: "/HelpAdd",
	    name: "HelpAdd",
	    meta: {
	        title: "使用帮助添加",
	        showBread: true,
	    },
	    component: () => import("../views/News/HelpAdd.vue"),
	},
	{
	    path: "/HelpEdit",
	    name: "HelpEdit",
	    meta: {
	        title: "使用帮助编辑",
	        showBread: true,
	    },
	    component: () => import("../views/News/HelpEdit.vue"),
	},
    {
        path: "/News/Mail",
        name: "Mail",
        meta: {
            title: "站内信",
        },
        component: () => import("../views/News/Mail.vue"),
    },
    
    {
        path: "/ChangePass",
        name: "ChangePass",
        meta: {
            title: "修改密码",
        },
        component: () => import("../views/ChangePass.vue"),
    },
    {
        path: "/Page403",
        name: "Page403",
        meta: {
            title: "页面403",
        },
        component: () => import("../views/Page403.vue"),
    },
    {
        path: "/:pathMatch(.*)*", // 代替vue2的通配符path: "*",
        name: "Page404",
        meta: {
            title: "页面404",
        },
        component: () => import("../views/Page404.vue"),
    },

	{
		path: "/area/area",
		name: "area",
		meta: {
			title: "大区管理",
		},
		component: () => import("@views/area/area.vue"),
	},
	{
		path: "/shop/shop",
		name: "shop",
		meta: {
			title: "门店管理"
		},
		component: () => import("@views/shop/shop.vue"),
	},
	{
		path: "/minArea/minArea",
		name: "minArea",
		meta: {
			title: "小区管理",
		},
		component: () => import("@views/minArea/minArea.vue"),
	},
	{
		path: "/minAreaUnit/minAreaUnit",
		name: "minAreaUnit",
		meta: {
			title: "小区单元",
		},
		component: () => import("@views/minAreaUnit/minAreaUnit.vue"),
	},
	{
		path: "/subway/subway",
		name: "subway",
		meta: {
			title: "地铁管理",
		},
		component: () => import("@views/subway/subway.vue"),
	},
	{
		path: "/subwayStation/subwayStation",
		name: "subwayStation",
		meta: {
			title: "地铁站点",
		},
		component: () => import("@views/subwayStation/subwayStation.vue"),
	},
	{
		path: "/houseTag/houseTag",
		name: "houseTag",
		meta: {
			title: "房源标签",
		},
		component: () => import("@views/houseTag/houseTag.vue"),
	},
	{
		path: "/houseType/houseType",
		name: "houseType",
		meta: {
			title: "房源类型",
		},
		component: () => import("@views/houseType/houseType.vue"),
	},
	{
		path: "/pianqu/pianqu",
		name: "pianqu",
		meta: {
			title: "片区管理",
		},
		component: () => import("@/views/pianqu/pianqu.vue"),
	},
	{
		path: "/message/message",
		name: "message",
		meta: {
			title: "信息",
		},
		component: () => import("@/views/message/message.vue"),
	},
	{
		path: "/guanJia/guanJia",
		name: "guanJia",
		meta: {
			title: "管家列表",
		},
		component: () => import("@/views/guanJia/guanJia.vue"),
	},
	{
		path: "/article/article",
		name: "article",
		meta: {
			title: "内容管理",
		},
		component: () => import("@/views/article/article.vue"),
	},
	{
		path: "/article/articleDetail",
		name: "articleDetail",
		meta: {
			title: "内容详情",
			showBread: true,
		},
		component: () => import("@/views/article/articleDetail.vue"),
	},
	{
		path: "/finance/config",
		name: "financeConfig",
		meta: {
			title: "佣金配置"
		},
		component: () => import("@/views/finance/config.vue"),
	},
	{
		path: "/houseNew/houseNew",
		name: "houseNew",
		meta: {
			title: "新房楼盘",
		},
		component: () => import("@/views/houseNew/houseNew.vue"),
	},
	{
		path: "/houseNew/houseNewDetail",
		name: "houseNewDetail",
		meta: {
			title: "新房楼盘详情",
			showBread: true,
		},
		component: () => import("@/views/houseNew/houseNewDetail.vue"),
	},
	{
		path: "/houseNewDong/houseNewDong",
		name: "houseNewDong",
		meta: {
			title: "新房楼盘楼栋",
		},
		component: () => import("@/views/houseNewDong/houseNewDong.vue"),
	},
	{
		path: "/houseNewHu/houseNewHu",
		name: "houseNewHu",
		meta: {
			title: "新房楼盘户型",
		},
		component: () => import("@/views/houseNewHu/houseNewHu.vue"),
	},
	{
		path: "/banner/banner",
		name: "banner",
		meta: {
			title: "轮播图",
		},
		component: () => import("@/views/banner/banner.vue"),
	},
	{
		path: "/serviceTel/serviceTel",
		name: "serviceTel",
		meta: {
			title: "客服电话",
		},
		component: () => import("@/views/serviceTel/serviceTel.vue"),
	},
	{
		path: "/houseRent/houseRent",
		name: "houseRent",
		meta: {
			title: "出租房源",
		},
		component: () => import("@/views/houseRent/houseRent.vue"),
	},
	{
		path: "/houseRent/houseRentDetail",
		name: "houseRentDetail",
		meta: {
			title: "出租房源详情",
			showBread: true,
		},
		component: () => import("@/views/houseRent/houseRentDetail.vue"),
	},
]

const router = createRouter({
	history: createWebHashHistory(),
    routes,
})

// 路由拦截
router.beforeEach((to, from, next) => {
	const token = localStorage.getItem("token")
	if (to.name !== 'Login' && !token) {
		//将用户重定向到登录页面
		next({path:'/'})
		return
	}
	if(to.query.metaTitle){
		to.meta.showBread = true
		to.meta.title = to.query.metaTitle
	}
	if (to.meta.title) {
        document.title = to.meta.title + ''
    }

    next()
})

export default router
